package approve.action;

import java.net.URLEncoder;
import java.sql.ResultSet;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import memo.action.Memo_listview;
import model.pojo.Employee;
import models.util.MySqlDataAccessHelper;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.Shader;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.util.AttributeSet;
import android.util.Log;
import android.view.InflateException;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.view.LayoutInflater.Factory;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.Button;
import android.widget.LinearLayout.LayoutParams;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.Spinner;
import android.widget.TextView;
import approve.adapter.App_Adapter_AddRefer;
import approve.adapter.App_Pop_AdapterApproverAll;
import approve.adapter.ListApproveAdapter;
import approve.adapter.ListEmployeeAdapter;
import approve.dao.ApproveDocDao;
import approve.dao.ListApproveDAO;
import approve.dao.ListReferenceDAO;
import approve.dao.NotApproveDAO;
import approve.model.Approvedoc;
import approve.model.DepartmentLang;
import approve.model.ListApprove;
import approve.model.ListEmployee;
import approve.model.ListLabel;

public class App_ViewForm12 extends Activity{
	TextView logout,username,home,welcome,titlehome,tvtitle,lbtitle,tvcreatdate,lbcreatedate,tvwriter,
	lbwriter,tvemployee,lbemployee,tvlocal,lblocal,tvtripdate,lbtripdate,lbcontent,tvtotal,
	lbtotal,tvlistapprove,lblistapprove,tvcomment,lbcomment,lbdes,tvdes,tvlinefunction;
	EditText etcomment;
	ImageView imiaccept,imidecline,imiaddrefer,imidelete,imisend,imiRestore;
	Button buttonBack,tvimiaccept,tvimidecline,tvimiaddrefer,tvimisend,tvimidelete,btshowlist,tvimiRestore;
	ListView lvapprove;
	
	ListLabel label ;
	
	public ListView getLvapprove() {
		return lvapprove;
	}

	public void setLvapprove(ListView lvapprove) {
		this.lvapprove = lvapprove;
	}

	int totalHeight_lstapp = 0;
	ViewGroup.LayoutParams params_lstapp;
	LinearLayout lnlayout;
	Approvedoc approvedoc = new Approvedoc();
	ListApproveAdapter adapterApprover;

	WebView tvcontent;

	String functionview="view",parentview;
	List<ListApprove> approverdata;

	//	private LinearLayout linProgressBar;
	private final Handler uiHandler=new Handler();
	private boolean isUpdateRequired=false;
	TextView tvwaiting;
	LayoutInflater inflaterwaiting;
	View textEntryViewwaiting;
	AlertDialog.Builder builderwaiting;
	AlertDialog alertwaiting;

	int flagviewpopup=0;
	Bundle extras;

	//    Spinner lstdepart;
	Spinner lstdepart;
	ListView lstrefer;
	ArrayList<Employee> referlist=new ArrayList<Employee>();
	ArrayList<Employee> subreferlist;
	ArrayList<Employee> emlist=new ArrayList<Employee>();
	ArrayList<DepartmentLang> departlist= new ArrayList<DepartmentLang>();
	DepartmentLang departmentchoose = new DepartmentLang();
	ListEmployeeAdapter emadapter;
	App_Adapter_AddRefer referadapter;

	//pop_addapprover
	LayoutInflater inflater_pop_addapprover;
	View textEntryView_pop_addapprover;
	AlertDialog alert_pop_addapprover;
	ListView lv_pop_approver;
	AlertDialog.Builder builder_pop_addapprover;
	App_Pop_AdapterApproverAll chooseapproveradapter;
	List<ListEmployee> approverlist = new ArrayList<ListEmployee>();
	boolean fviewlistapp=false;
	
	public boolean isUpdateRequired() {
		return isUpdateRequired;
	}

	public void setUpdateRequired(boolean isUpdateRequired) {
		this.isUpdateRequired = isUpdateRequired;
	}

	public AlertDialog getAlertwaiting() {
		return alertwaiting;
	}

	public void setAlertwaiting(AlertDialog alertwaiting) {
		this.alertwaiting = alertwaiting;
	}

	public Handler getUiHandler() {
		return uiHandler;
	}

	public ArrayList<Employee> getReferlist() {
		return referlist;
	}

	public void setReferlist(ArrayList<Employee> referlist) {
		this.referlist = referlist;
	}

	public App_Adapter_AddRefer getReferadapter() {
		return referadapter;
	}

	public void setReferadapter(App_Adapter_AddRefer referadapter) {
		this.referadapter = referadapter;
	}

	public App_Pop_AdapterApproverAll getChooseapproveradapter() {
		return chooseapproveradapter;
	}

	public void setChooseapproveradapter(
			App_Pop_AdapterApproverAll chooseapproveradapter) {
		this.chooseapproveradapter = chooseapproveradapter;
	}

	public List<ListEmployee> getApproverlist() {
		return approverlist;
	}

	public void setApproverlist(List<ListEmployee> approverlist) {
		this.approverlist = approverlist;
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		try{
			initall();
		}catch(Exception e){
			e.printStackTrace();
			Intent i = getBaseContext().getPackageManager().getLaunchIntentForPackage( getBaseContext().getPackageName() );
			i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			startActivity(i);
		}
	}
	
	private void initall(){
		setContentView(R.layout.app_viewform12);
		loadExtra();
		initalldata();
		adapterApprover = new ListApproveAdapter(App_ViewForm12.this, approverdata, LoginActivity.lang, 
				LoginActivity.emp, LoginActivity.database, LoginActivity.typeLang,12);

		getInitAttribute();

		buttonBack.setOnClickListener(processBack);

		tvimiaccept.setOnClickListener(tvimiacceptOnClick);
		tvimidecline.setOnClickListener(tvimideclineOnClick);
		tvimiaddrefer.setOnClickListener(tvimiaddreferOnClick);
		imiaccept.setOnClickListener(tvimiacceptOnClick);
		imidecline.setOnClickListener(tvimideclineOnClick);
		imiaddrefer.setOnClickListener(tvimiaddreferOnClick);

		tvimidelete.setOnClickListener(tvimideleteOnClick);
		tvimisend.setOnClickListener(tvimisendOnClick);
		imidelete.setOnClickListener(tvimideleteOnClick);
		imisend.setOnClickListener(tvimisendOnClick);
		
		tvimiRestore.setOnClickListener(tvimiRestoreOnclick);
		imiRestore.setOnClickListener(tvimiRestoreOnclick);

		RelativeLayout relativeLayout = (RelativeLayout)findViewById(R.id.relativeTitle);

		Resources res = getResources();
		final BitmapDrawable background = (BitmapDrawable) res.getDrawable(R.drawable.bg_menu_item);
		background.setTileModeX(Shader.TileMode.REPEAT);
		background.setTileModeY(Shader.TileMode.REPEAT);
		background.setDither(true);
		relativeLayout.setBackgroundDrawable(background);
		
	}
	
	private OnClickListener tvimiacceptOnClick = new OnClickListener() {

		@Override
		public void onClick(View v) {

			if(functionview.equals("exec")){
				if(parentview.equals("notApprove")){
					accept();
				}else if(parentview.equals("referWait")){
					acceptRefer();
				}
			}
		}
	};

	private OnClickListener tvimideclineOnClick= new OnClickListener() {

		@Override
		public void onClick(View v) {
			decline();
		}
	};

	private OnClickListener tvimiaddreferOnClick = new OnClickListener() {

		@Override
		public void onClick(View v) {
			if(flagviewpopup==0){
				flagviewpopup=1;
				processAddRefer();
			}

		}
	};


	private OnClickListener tvimideleteOnClick = new OnClickListener() {

		@Override
		public void onClick(View v) {
			if(parentview.equals("my_declineDoc")){
				view_declineDoc_delete();
			}else if(parentview.equals("my_saveDoc")){
				view_saveDoc_delete();
			}
		}
	};


	private OnClickListener tvimisendOnClick = new OnClickListener() {

		@Override
		public void onClick(View v) {
			if(flagviewpopup==0){
				flagviewpopup=1;
				view_send();
			}
		}
	};
	
	private OnClickListener tvimiRestoreOnclick = new OnClickListener() {
		
		@Override
		public void onClick(View arg0) {
			if(flagviewpopup==0){
				flagviewpopup=1;
				processRestore();
			}
		}
	};
	
	

	public void loadExtra() {
		extras = getIntent().getExtras();
		if (extras != null) {
			parentview=(String)extras.get("parentview");
			functionview=(String)extras.getString("functionview");
			approvedoc=(Approvedoc) extras.get("approvedoc");
			label = (ListLabel)extras.get("label");
		}
	}

	
	
	private void initalldata(){
		approverdata = new ArrayList<ListApprove>();
		referlist=new ArrayList<Employee>();
		MySqlDataAccessHelper mysql = new MySqlDataAccessHelper();
		try{
			mysql.open(LoginActivity.database);
			String sql="select employee.FullName from employee where employee.IDEmployee='"+approvedoc.getiDEmployee()+"'";
			ResultSet rs = mysql.executeQuery(sql);
			if(rs.next()){
				approvedoc.setFullName(rs.getString("FullName"));
			}else{
				approvedoc.setFullName("");
			}

			if(approvedoc.getiDStatus()==6){
//				sql = "SELECT l.IDEmployee,l.Order,l.IDStatus,l.Description ,FullName,l.DateApprove FROM listapprove l, employee WHERE l.IDEmployee = employee.IDEmployee and  l.IDGroupApprove ='"+approvedoc.getiDGroupApprove()+"' ORDER BY l.Order ASC;";
				sql = "SELECT l.IDEmployee,l.Order,l.IDStatus,l.Description ,FullName, st.StatusName ,l.DateApprove FROM listapprove l, employee,`status` st WHERE l.IDEmployee = employee.IDEmployee and l.IDStatus = st.IDStatus and  l.IDGroupApprove ='"+approvedoc.getiDGroupApprove()+"' ORDER BY l.Order ASC;";
				rs = mysql.executeQuery(sql);
				while(rs.next()){
					String sql1="SELECT l.id_employee,employee.FullName FROM list_reference l, employee WHERE l.id_manager='"+rs.getString("IDEmployee")+"' and l.id_employee=employee.IDEmployee and  l.id_group ='"+approvedoc.getiDGroupApprove()+"'";
					ResultSet rs1= mysql.executeQuery(sql1);
					int i=0;
					String s="";
					if(rs.getString("IDEmployee").equals(LoginActivity.emp.getIdemployee())){
						while(rs1.next()){
							referlist.add(new Employee(rs1.getString("id_employee"), rs1.getString("FullName"),true));
							if(i==0){
								s=rs1.getString("FullName");
							}else{
								s+="; "+rs1.getString("FullName");
							}
							i++;
						}
					}else{
						while(rs1.next()){
							if(i==0){
								s=rs1.getString("FullName");
							}else{
								s+="; "+rs1.getString("FullName");
							}
							i++;
						}
					}

					ListApprove one= new ListApprove();
					one.setOrder(rs.getInt("Order"));
					one.setiDStatus(rs.getInt("IDStatus"));
					one.setDescription(rs.getString("Description"));
					one.setEmname(rs.getString("FullName"));
					one.setDateApprove(rs.getTimestamp("DateApprove"));
					one.setStatusname(rs.getString("StatusName"));
					one.setListrefer(s);
					approverdata.add(one);
				}
			}else{
				sql = "SELECT l.IDEmployee,l.Order,l.IDStatus,l.Description ,FullName, st.StatusName ,l.DateApprove FROM listapprove l, employee,`status` st WHERE l.IDEmployee = employee.IDEmployee and l.IDStatus = st.IDStatus and  l.IDGroupApprove ='"+approvedoc.getiDGroupApprove()+"' ORDER BY l.Order ASC;";
				rs = mysql.executeQuery(sql);
				while(rs.next()){
					String sql1="SELECT l.id_employee,employee.FullName FROM list_reference l, employee WHERE l.id_manager='"+rs.getString("IDEmployee")+"' and l.id_employee=employee.IDEmployee and  l.id_group ='"+approvedoc.getiDGroupApprove()+"'";
					ResultSet rs1= mysql.executeQuery(sql1);
					int i=0;
					String s="";
					if(rs.getString("IDEmployee").equals(LoginActivity.emp.getIdemployee())){
						while(rs1.next()){
							referlist.add(new Employee(rs1.getString("id_employee"), rs1.getString("FullName"),true));
							if(i==0){
								s=rs1.getString("FullName");
							}else{
								s+="; "+rs1.getString("FullName");
							}
							i++;
						}
					}else{
						while(rs1.next()){
							if(i==0){
								s=rs1.getString("FullName");
							}else{
								s+="; "+rs1.getString("FullName");
							}
							i++;
						}
					}

					ListApprove one= new ListApprove();
					one.setOrder(rs.getInt("Order"));
					one.setiDStatus(rs.getInt("IDStatus"));
					one.setDescription(rs.getString("Description"));
					one.setEmname(rs.getString("FullName"));
					one.setDateApprove(rs.getTimestamp("DateApprove"));
					one.setStatusname(rs.getString("StatusName"));
					one.setListrefer(s);
					approverdata.add(one);
				}
			}
			subreferlist=new ArrayList<Employee>();
			subreferlist.addAll(referlist);
			rs.close();
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			mysql.close();
		}
	}

	private void getInitAttribute(){
		int lbwidth=LoginActivity.screenwidth/3+10;
		int tvwidth=LoginActivity.screenwidth-LoginActivity.screenwidth/3;
		DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		DateFormat df1 = new SimpleDateFormat("yyyy-MM-dd");

		logout=(TextView)findViewById(R.id.logout);
		logout.setText(LoginActivity.lang.getString("Logout"));

		username=(TextView)findViewById(R.id.username);
		username.setText(LoginActivity.emp.getUserName());

		welcome = (TextView)findViewById(R.id.welcome);
		welcome.setText(LoginActivity.lang.getString("ac_Welcome"));


		logout.setOnClickListener(listenerLogout);

		buttonBack = (Button)findViewById(R.id.buttonBack);
		titlehome=(TextView)findViewById(R.id.titlehome);
		if(parentview.equals("notApprove")){
			titlehome.setText(LoginActivity.lang.getString("not-approved-document"));
		}else if(parentview.equals("approveDoc")){
			titlehome.setText(LoginActivity.lang.getString("document_approval"));
		}else if(parentview.equals("declineDoc") ){
			titlehome.setText(LoginActivity.lang.getString("docDecline"));
		}else if(parentview.equals("referApprove")){
			titlehome.setText(LoginActivity.lang.getString("reference_document")+"-"+LoginActivity.lang.getString("empApprove"));
		}else if(parentview.equals("referWait")){
			titlehome.setText(LoginActivity.lang.getString("reference_document")+"-"+LoginActivity.lang.getString("empNotApprove"));
		}else if(parentview.equals("docPending")){
			titlehome.setText(LoginActivity.lang.getString("pending-document"));
		}else if(parentview.equals("meetingPending")){
			titlehome.setText(LoginActivity.lang.getString("metting_pending"));
		}else if(parentview.equals("my_approveDoc")){
			titlehome.setText(LoginActivity.lang.getString("mydocappro"));
		}else if( parentview.equals("my_declineDoc")){
			titlehome.setText(LoginActivity.lang.getString("mydeclinedoc"));
		}else if(parentview.equals("my_sendingDoc")){
			titlehome.setText(LoginActivity.lang.getString("mydocsending"));
		}else if(parentview.equals("my_saveDoc")){
			titlehome.setText(LoginActivity.lang.getString("mydocsave"));
		}else if(parentview.equals("my_meetingPending")){
			titlehome.setText(LoginActivity.lang.getString("mymeetingdcsending"));
		}else if(parentview.equals("recycle_pending")){
			titlehome.setText(LoginActivity.lang.getString("recycle_bin")+"-"+LoginActivity.lang.getString("sending_document"));
		}else if(parentview.equals("recyle_app")){
			titlehome.setText(LoginActivity.lang.getString("recycle_bin")+"-"+LoginActivity.lang.getString("receiveddocument"));
		}else if(parentview.equals("library")){
			titlehome.setText(LoginActivity.lang.getString("library_document"));
		}

		if(functionview.equals("exec")){
			if(parentview.equals("notApprove")){
				tvlinefunction=(TextView)findViewById(R.id.tvlinefunction12);
				tvlinefunction.setVisibility(View.VISIBLE);
				imiaccept=(ImageView)findViewById(R.id.imiaccept12);
				imidecline=(ImageView)findViewById(R.id.imidecline12);
				imiaddrefer=(ImageView)findViewById(R.id.imiaddrefer12);
				tvimiaccept=(Button)findViewById(R.id.tvimiaccept12);
				tvimidecline=(Button)findViewById(R.id.tvimidecline12);
				tvimiaddrefer=(Button)findViewById(R.id.tvimiaddrefer12);
				tvimiRestore = (Button)findViewById(R.id.tvimiRestore12);
				tvimiRestore.setVisibility(View.GONE);
				imiRestore = (ImageView)findViewById(R.id.imiRestore12);
				imiRestore.setVisibility(View.GONE);
				imiaccept.setVisibility(View.VISIBLE);
				imiaddrefer.setVisibility(View.VISIBLE);
				imidecline.setVisibility(View.VISIBLE);
				tvimiaccept.setVisibility(View.VISIBLE);
				tvimidecline.setVisibility(View.VISIBLE);
				tvimiaddrefer.setVisibility(View.VISIBLE);
				tvimiaccept.setText(LoginActivity.lang.getString("accept"));
				tvimidecline.setText(LoginActivity.lang.getString("Decline"));
				tvimiaddrefer.setText(LoginActivity.lang.getString("reference_app"));

				tvimidelete=(Button)findViewById(R.id.tvimidelete12);
				tvimisend=(Button)findViewById(R.id.tvimisend12);
				imidelete=(ImageView)findViewById(R.id.imidelete12);
				imisend=(ImageView)findViewById(R.id.imisend12);
				tvimidelete.setVisibility(View.GONE);
				tvimisend.setVisibility(View.GONE);
				imidelete.setVisibility(View.GONE);
				imisend.setVisibility(View.GONE);

			}else if(parentview.equals("referWait")){
				tvlinefunction=(TextView)findViewById(R.id.tvlinefunction12);
				tvlinefunction.setVisibility(View.VISIBLE);
				imiaccept=(ImageView)findViewById(R.id.imiaccept12);
				imidecline=(ImageView)findViewById(R.id.imidecline12);
				imiaddrefer=(ImageView)findViewById(R.id.imiaddrefer12);
				tvimiaccept=(Button)findViewById(R.id.tvimiaccept12);
				tvimidecline=(Button)findViewById(R.id.tvimidecline12);
				tvimiaddrefer=(Button)findViewById(R.id.tvimiaddrefer12);
				tvimiRestore = (Button)findViewById(R.id.tvimiRestore12);
				tvimiRestore.setVisibility(View.GONE);
				imiRestore = (ImageView)findViewById(R.id.imiRestore12);
				imiRestore.setVisibility(View.GONE);
				imiaccept.setVisibility(View.VISIBLE);
				imiaddrefer.setVisibility(View.GONE);
				imidecline.setVisibility(View.GONE);
				tvimiaccept.setVisibility(View.VISIBLE);
				tvimidecline.setVisibility(View.GONE);
				tvimiaddrefer.setVisibility(View.GONE);
				tvimiaccept.setText(LoginActivity.lang.getString("accept"));

				tvimidelete=(Button)findViewById(R.id.tvimidelete12);
				tvimisend=(Button)findViewById(R.id.tvimisend12);
				imidelete=(ImageView)findViewById(R.id.imidelete12);
				imisend=(ImageView)findViewById(R.id.imisend12);
				tvimidelete.setVisibility(View.GONE);
				tvimisend.setVisibility(View.GONE);
				imidelete.setVisibility(View.GONE);
				imisend.setVisibility(View.GONE);
			}
		}else if(functionview.equals("view_delete")){
			tvlinefunction=(TextView)findViewById(R.id.tvlinefunction12);
			tvlinefunction.setVisibility(View.VISIBLE);
			imiaccept=(ImageView)findViewById(R.id.imiaccept12);
			imidecline=(ImageView)findViewById(R.id.imidecline12);
			imiaddrefer=(ImageView)findViewById(R.id.imiaddrefer12);
			tvimiaccept=(Button)findViewById(R.id.tvimiaccept12);
			tvimidecline=(Button)findViewById(R.id.tvimidecline12);
			tvimiaddrefer=(Button)findViewById(R.id.tvimiaddrefer12);
			tvimiRestore = (Button)findViewById(R.id.tvimiRestore12);
			tvimiRestore.setVisibility(View.GONE);
			imiRestore = (ImageView)findViewById(R.id.imiRestore12);
			imiRestore.setVisibility(View.GONE);
			imiaccept.setVisibility(View.GONE);
			imiaddrefer.setVisibility(View.GONE);
			imidecline.setVisibility(View.GONE);
			tvimiaccept.setVisibility(View.GONE);
			tvimidecline.setVisibility(View.GONE);
			tvimiaddrefer.setVisibility(View.GONE);

			tvimidelete=(Button)findViewById(R.id.tvimidelete12);
			tvimisend=(Button)findViewById(R.id.tvimisend12);
			imidelete=(ImageView)findViewById(R.id.imidelete12);
			imisend=(ImageView)findViewById(R.id.imisend12);
			tvimidelete.setVisibility(View.VISIBLE);
			tvimisend.setVisibility(View.GONE);
			imidelete.setVisibility(View.VISIBLE);
			imisend.setVisibility(View.GONE);
			tvimidelete.setText(LoginActivity.lang.getString("Delete"));
		}else if(functionview.equals("view_delete_exec_save")){
			tvlinefunction=(TextView)findViewById(R.id.tvlinefunction12);
			tvlinefunction.setVisibility(View.VISIBLE);
			imiaccept=(ImageView)findViewById(R.id.imiaccept12);
			imidecline=(ImageView)findViewById(R.id.imidecline12);
			imiaddrefer=(ImageView)findViewById(R.id.imiaddrefer12);
			tvimiaccept=(Button)findViewById(R.id.tvimiaccept12);
			tvimidecline=(Button)findViewById(R.id.tvimidecline12);
			tvimiaddrefer=(Button)findViewById(R.id.tvimiaddrefer12);
			tvimiRestore = (Button)findViewById(R.id.tvimiRestore12);
			tvimiRestore.setVisibility(View.GONE);
			imiRestore = (ImageView)findViewById(R.id.imiRestore12);
			imiRestore.setVisibility(View.GONE);
			imiaccept.setVisibility(View.GONE);
			imiaddrefer.setVisibility(View.GONE);
			imidecline.setVisibility(View.GONE);
			tvimiaccept.setVisibility(View.GONE);
			tvimidecline.setVisibility(View.GONE);
			tvimiaddrefer.setVisibility(View.GONE);

			tvimidelete=(Button)findViewById(R.id.tvimidelete12);
			tvimisend=(Button)findViewById(R.id.tvimisend12);
			imidelete=(ImageView)findViewById(R.id.imidelete12);
			imisend=(ImageView)findViewById(R.id.imisend12);
			tvimidelete.setVisibility(View.VISIBLE);
			tvimisend.setVisibility(View.VISIBLE);
			imidelete.setVisibility(View.VISIBLE);
			imisend.setVisibility(View.VISIBLE);
			tvimidelete.setText(LoginActivity.lang.getString("Delete"));
			tvimisend.setText(LoginActivity.lang.getString("sendapprover"));
		}else if(functionview.equals("restore")){
			tvimiRestore = (Button)findViewById(R.id.tvimiRestore12);
			tvimiRestore.setText(LoginActivity.lang.getString("restore"));
			imiRestore = (ImageView)findViewById(R.id.imiRestore12);
			imiRestore.setVisibility(View.VISIBLE);
			
			tvlinefunction=(TextView)findViewById(R.id.tvlinefunction12);
			tvlinefunction.setVisibility(View.VISIBLE);
			imiaccept=(ImageView)findViewById(R.id.imiaccept12);
			imidecline=(ImageView)findViewById(R.id.imidecline12);
			imiaddrefer=(ImageView)findViewById(R.id.imiaddrefer12);
			tvimiaccept=(Button)findViewById(R.id.tvimiaccept12);
			tvimidecline=(Button)findViewById(R.id.tvimidecline12);
			tvimiaddrefer=(Button)findViewById(R.id.tvimiaddrefer12);
			imiaccept.setVisibility(View.GONE);
			imiaddrefer.setVisibility(View.GONE);
			imidecline.setVisibility(View.GONE);
			tvimiaccept.setVisibility(View.GONE);
			tvimidecline.setVisibility(View.GONE);
			tvimiaddrefer.setVisibility(View.GONE);

			tvimidelete=(Button)findViewById(R.id.tvimidelete12);
			tvimisend=(Button)findViewById(R.id.tvimisend12);
			imidelete=(ImageView)findViewById(R.id.imidelete12);
			imisend=(ImageView)findViewById(R.id.imisend12);
			tvimidelete.setVisibility(View.GONE);
			tvimisend.setVisibility(View.GONE);
			imidelete.setVisibility(View.GONE);
			imisend.setVisibility(View.GONE);
			
		}
		else if(functionview.equals("view_recyle")){
			tvimiRestore = (Button)findViewById(R.id.tvimiRestore12);
			tvimiRestore.setVisibility(View.GONE);
			imiRestore = (ImageView)findViewById(R.id.imiRestore12);
			imiRestore.setVisibility(View.GONE);
			tvlinefunction=(TextView)findViewById(R.id.tvlinefunction12);
			tvlinefunction.setVisibility(View.VISIBLE);
			imiaccept=(ImageView)findViewById(R.id.imiaccept12);
			imidecline=(ImageView)findViewById(R.id.imidecline12);
			imiaddrefer=(ImageView)findViewById(R.id.imiaddrefer12);
			tvimiaccept=(Button)findViewById(R.id.tvimiaccept12);
			tvimidecline=(Button)findViewById(R.id.tvimidecline12);
			tvimiaddrefer=(Button)findViewById(R.id.tvimiaddrefer12);
			imiaccept.setVisibility(View.GONE);
			imiaddrefer.setVisibility(View.GONE);
			imidecline.setVisibility(View.GONE);
			tvimiaccept.setVisibility(View.GONE);
			tvimidecline.setVisibility(View.GONE);
			tvimiaddrefer.setVisibility(View.GONE);

			tvimidelete=(Button)findViewById(R.id.tvimidelete12);
			tvimisend=(Button)findViewById(R.id.tvimisend12);
			imidelete=(ImageView)findViewById(R.id.imidelete12);
			imisend=(ImageView)findViewById(R.id.imisend12);
			tvimidelete.setVisibility(View.GONE);
			tvimisend.setVisibility(View.GONE);
			imidelete.setVisibility(View.GONE);
			imisend.setVisibility(View.GONE);
			
		}else if(functionview.equals("view_label")){
			tvlinefunction=(TextView)findViewById(R.id.tvlinefunction12);
			tvlinefunction.setVisibility(View.GONE);
			imiaccept=(ImageView)findViewById(R.id.imiaccept12);
			imidecline=(ImageView)findViewById(R.id.imidecline12);
			imiaddrefer=(ImageView)findViewById(R.id.imiaddrefer12);
			tvimiaccept=(Button)findViewById(R.id.tvimiaccept12);
			tvimidecline=(Button)findViewById(R.id.tvimidecline12);
			tvimiaddrefer=(Button)findViewById(R.id.tvimiaddrefer12);
			tvimiRestore = (Button)findViewById(R.id.tvimiRestore12);
			tvimiRestore.setVisibility(View.GONE);
			imiaccept.setVisibility(View.GONE);
			imiaddrefer.setVisibility(View.GONE);
			imidecline.setVisibility(View.GONE);
			tvimiaccept.setVisibility(View.GONE);
			tvimidecline.setVisibility(View.GONE);
			tvimiaddrefer.setVisibility(View.GONE);
			imiRestore = (ImageView)findViewById(R.id.imiRestore12);
			imiRestore.setVisibility(View.GONE);
			tvimidelete=(Button)findViewById(R.id.tvimidelete12);
			tvimisend=(Button)findViewById(R.id.tvimisend12);
			imidelete=(ImageView)findViewById(R.id.imidelete12);
			imisend=(ImageView)findViewById(R.id.imisend12);
			tvimidelete.setVisibility(View.GONE);
			tvimisend.setVisibility(View.GONE);
			imidelete.setVisibility(View.GONE);
			imisend.setVisibility(View.GONE);
		}
		else{
			tvlinefunction=(TextView)findViewById(R.id.tvlinefunction12);
			tvlinefunction.setVisibility(View.GONE);
			imiaccept=(ImageView)findViewById(R.id.imiaccept12);
			imidecline=(ImageView)findViewById(R.id.imidecline12);
			imiaddrefer=(ImageView)findViewById(R.id.imiaddrefer12);
			tvimiaccept=(Button)findViewById(R.id.tvimiaccept12);
			tvimidecline=(Button)findViewById(R.id.tvimidecline12);
			tvimiaddrefer=(Button)findViewById(R.id.tvimiaddrefer12);
			tvimiRestore = (Button)findViewById(R.id.tvimiRestore12);
			tvimiRestore.setVisibility(View.GONE);
			imiaccept.setVisibility(View.GONE);
			imiaddrefer.setVisibility(View.GONE);
			imidecline.setVisibility(View.GONE);
			tvimiaccept.setVisibility(View.GONE);
			tvimidecline.setVisibility(View.GONE);
			tvimiaddrefer.setVisibility(View.GONE);
			imiRestore = (ImageView)findViewById(R.id.imiRestore12);
			imiRestore.setVisibility(View.GONE);
			tvimidelete=(Button)findViewById(R.id.tvimidelete12);
			tvimisend=(Button)findViewById(R.id.tvimisend12);
			imidelete=(ImageView)findViewById(R.id.imidelete12);
			imisend=(ImageView)findViewById(R.id.imisend12);
			tvimidelete.setVisibility(View.GONE);
			tvimisend.setVisibility(View.GONE);
			imidelete.setVisibility(View.GONE);
			imisend.setVisibility(View.GONE);
			
		}

		lbtitle=(TextView)findViewById(R.id.lbtitle);
		lbtitle.setText(LoginActivity.lang.getString("title")+": ");
		tvtitle=(TextView)findViewById(R.id.tvtitle);
		tvtitle.setText(approvedoc.getTitle());
		lbtitle.setWidth(lbwidth);
		tvtitle.setWidth(tvwidth);

		lbcreatedate=(TextView)findViewById(R.id.lbcreatdate);
		lbcreatedate.setText(LoginActivity.lang.getString("created-date")+": ");
		tvcreatdate=(TextView)findViewById(R.id.tvcreatdate);

		tvcreatdate.setText(df.format(approvedoc.getTimecreate()));
		lbcreatedate.setWidth(lbwidth);
		tvcreatdate.setWidth(tvwidth);

		lbwriter=(TextView)findViewById(R.id.lbwriter);
		lbwriter.setText(LoginActivity.lang.getString("writer")+": ");
		tvwriter=(TextView)findViewById(R.id.tvwriter);
		tvwriter.setText(approvedoc.getFullName());
		lbwriter.setWidth(lbwidth);
		tvwriter.setWidth(tvwidth);

		lbdes=(TextView)findViewById(R.id.lbdes);
		lbdes.setText(LoginActivity.lang.getString("Description")+": ");
		tvdes=(TextView)findViewById(R.id.tvdes);
		tvdes.setText(approvedoc.getDescription());
		lbdes.setWidth(lbwidth);
		tvdes.setWidth(tvwidth);

		lbemployee=(TextView)findViewById(R.id.lbemployee);
		lbemployee.setText(LoginActivity.lang.getString("implementation")+": ");
		tvemployee=(TextView)findViewById(R.id.tvemployee);
		tvemployee.setText(approvedoc.getEmployeePerforment());
		lbemployee.setWidth(lbwidth);
		tvemployee.setWidth(tvwidth);

		lblocal=(TextView)findViewById(R.id.lblocal);
		lblocal.setText(LoginActivity.lang.getString("where")+": ");
		tvlocal=(TextView)findViewById(R.id.tvlocal);
		tvlocal.setText(approvedoc.getLocation());
		lblocal.setWidth(lbwidth);
		tvlocal.setWidth(tvwidth);

		lbtripdate=(TextView)findViewById(R.id.lbtripdate);
		lbtripdate.setText(LoginActivity.lang.getString("trip_date")+": ");
		tvtripdate=(TextView)findViewById(R.id.tvtripdate);
		if(approvedoc.getTripDate()==null){
			tvtripdate.setText("");
		}else{
			tvtripdate.setText(df1.format(approvedoc.getTripDate()));	
		}

		lbtripdate.setWidth(lbwidth);
		tvtripdate.setWidth(tvwidth);

		lbtotal=(TextView)findViewById(R.id.lbtotal);
		lbtotal.setText(LoginActivity.lang.getString("total_time")+": ");
		tvtotal=(TextView)findViewById(R.id.tvtotal);
		tvtotal.setText(approvedoc.getTotalTime());
		lbtotal.setWidth(lbwidth);
		tvtotal.setWidth(tvwidth);

		lbcontent=(TextView)findViewById(R.id.lbcontent);
		lbcontent.setText(LoginActivity.lang.getString("content")+": ");
		tvcontent=(WebView)findViewById(R.id.tvcontent);

		tvcontent.getSettings().setLoadWithOverviewMode(true);
		tvcontent.getSettings().setUseWideViewPort(true);
		tvcontent.getSettings().setJavaScriptEnabled(true);
		tvcontent.setBackgroundColor(Color.parseColor("#364b4c"));
		tvcontent.setClickable(false);
		tvcontent.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
//		tvcontent.getSettings().getBuiltInZoomControls();
		tvcontent.setHorizontalScrollBarEnabled(true);
		tvcontent.setScrollbarFadingEnabled(true);
		tvcontent.getSettings().setSupportZoom(false);
		tvcontent.getSettings().setBuiltInZoomControls(false);
//		tvcontent.setClickable(false);


		final String mimeType = "text/html";
		String header = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>";
		header += "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML Basic 1.1//EN\" \"http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd\">";
		header += "<html><head><meta name=\"viewport\" content=\"width=device-width,height=device-height, initial-scale=1.0, user-scalable=yes\"></head>" +
		"<body style=\"font-family:Arial, Helvetica, sans-serif; font-size:15px;!important\">";
		String str=header + "<font color='white'>"+ approvedoc.getContent()+"</font>" +"</body></html>";
		
		tvcontent.loadData(URLEncoder.encode(str).replaceAll("\\+"," "), mimeType,null);
		
		LinearLayout linerform12 = (LinearLayout)findViewById(R.id.linerform12);
		linerform12.setBackgroundColor(Color.parseColor("#364b4c"));


		lblistapprove=(TextView)findViewById(R.id.lblistapprove);
		lblistapprove.setText(LoginActivity.lang.getString("ListApprove")+": ");
		lblistapprove.setWidth(LoginActivity.screenwidth);
		lvapprove=(ListView)findViewById(R.id.lvapprove);
		lvapprove.setAdapter(adapterApprover);
		
		totalHeight_lstapp=0;
		for (int i = 0; i < adapterApprover.getCount(); i++) {
			View listItem = adapterApprover.getView(i, null, lvapprove);
			listItem.measure(0, 0);
			totalHeight_lstapp += listItem.getMeasuredHeight();
		}
		
		totalHeight_lstapp+= totalHeight_lstapp + (lvapprove.getDividerHeight() * (adapterApprover.getCount() - 1));
		params_lstapp = lvapprove.getLayoutParams();
		if(totalHeight_lstapp<=0){
			params_lstapp.height =0;
			lvapprove.setLayoutParams(params_lstapp);
		}else{
			if(totalHeight_lstapp<200){
				params_lstapp.height=android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
				lvapprove.setLayoutParams(params_lstapp);
			}else{
				params_lstapp.height=200;
				lvapprove.setLayoutParams(params_lstapp);
			}
		}
		
		
		lvapprove.setOnTouchListener(new OnTouchListener() {
			
			public boolean onTouch(View arg0, MotionEvent event) {

				if(event.getAction() == MotionEvent.ACTION_MOVE){
					lvapprove.scrollBy(0, 1);
				}
				
				return false;
			}
		});

		lbcomment=(TextView)findViewById(R.id.lbcomment);
		etcomment=(EditText)findViewById(R.id.etcomment);
		lbcomment.setText(LoginActivity.lang.getString("commentapproving")+": ");		
		lbcomment.setWidth(LoginActivity.screenwidth);
		etcomment.setWidth(LoginActivity.screenwidth);
		etcomment.setScrollbarFadingEnabled(true);

		if(functionview.equals("exec") && !parentview.equals("referWait")){			
			lbcomment.setVisibility(View.VISIBLE);
			etcomment.setVisibility(View.VISIBLE);
		}else{
			lbcomment.setVisibility(View.GONE);
			etcomment.setVisibility(View.GONE);
		}

		inflaterwaiting = (LayoutInflater) getApplicationContext().getSystemService(LAYOUT_INFLATER_SERVICE);          
		textEntryViewwaiting = inflaterwaiting.inflate(R.layout.waiting, null);
		tvwaiting=(TextView)textEntryViewwaiting.findViewById(R.id.TextView01);					
		tvwaiting.setText(LoginActivity.lang.getString("waiting")+"...");

		builderwaiting = new AlertDialog.Builder(App_ViewForm12.this);
		builderwaiting.setView(textEntryViewwaiting);
		builderwaiting.setCancelable(false);
		alertwaiting = builderwaiting.create();
	}
	

	private OnClickListener listenerLogout=new OnClickListener() {

		public void onClick(View v) {
			logout.setTextColor(Color.parseColor("#1188ff"));
			LoginActivity.flagruntimer=true;
			LoginActivity.soluong=0;
			LoginActivity.emp=new Employee();
			MainEApproval.mNotificationManager.cancel(MainEApproval.SIMPLE_NOTFICATION_ID);
			MainEApproval.timer.cancel();
			Intent i=new Intent(App_ViewForm12.this, LogoutActivity.class);
			startActivity(i);
			finish();
		}
	};

	public List<ListApprove> getAllListApproveByGroupID(){
		return ListApproveDAO.getApproversByGroupId_notallinfo(approvedoc.getiDGroupApprove(),LoginActivity.database);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		super.onCreateOptionsMenu(menu);
		MenuInflater inflater = new MenuInflater(getApplicationContext());

		if(LoginActivity.typeLang.equals("EN")){
			inflater.inflate(R.menu.option_main_menu, menu);
		}else if(LoginActivity.typeLang.equals("VN")){
			inflater.inflate(R.menu.option_main_menuvn, menu);
		}else{
			inflater.inflate(R.menu.option_main_menukr, menu);
		}

		setMenuBackground();
		return true;

	}

	protected void setMenuBackground(){
		Log.d("", "Enterting setMenuBackGround");  
		getLayoutInflater().setFactory( new Factory() {  

			@Override
			public View onCreateView(String name, Context context,
					AttributeSet attrs) {
				if ( name.equalsIgnoreCase( "com.android.internal.view.menu.IconMenuItemView" ) ) {  

					try { 
						LayoutInflater f = getLayoutInflater();  
						final View view = f.createView( name, null, attrs );  
						new Handler().post( new Runnable() {  
							public void run () {  
								view.setBackgroundResource( R.drawable.border_footer);  
							}  
						} );  
						return view;  
					}  
					catch ( InflateException e ) {}  
					catch ( ClassNotFoundException e ) {}  
				}  
				return null;  

			}  
		});  
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		if(LoginActivity.typeLang.equals("VN")){
			switch (item.getItemId()) {
			case R.id.menu_eappvn:
				processMenuEApproval();
				return true;
			case R.id.menu_primemovn:
				processMenuPrivateMemo();
				return true;
			default:
				return super.onOptionsItemSelected(item);
			}
		}else if(LoginActivity.typeLang.equals("KR")){
			switch (item.getItemId()) {
			case R.id.menu_eappkr:
				processMenuEApproval();
				return true;
			case R.id.menu_primemokr:
				processMenuPrivateMemo();
				return true;
			default:
				return super.onOptionsItemSelected(item);
			}
		}else{
			switch (item.getItemId()) {
			case R.id.menu_eapp:
				processMenuEApproval();
				return true;
			case R.id.menu_primemo:
				processMenuPrivateMemo();
				return true;
			default:
				return super.onOptionsItemSelected(item);
			}
		}

	}
	public void processMenuEApproval(){
		Intent intent = new Intent(App_ViewForm12.this,MainEApproval.class);
		startActivity(intent);
		finish();
	}

	public void processMenuPrivateMemo(){
		Intent intent = new Intent(App_ViewForm12.this,Memo_listview.class);
		startActivity(intent);
		finish();
	}

	void accept(){
		AlertDialog.Builder alertDialog = new AlertDialog.Builder(App_ViewForm12.this);
		alertDialog.setTitle(LoginActivity.lang.getString("accept"));
		alertDialog.setMessage(LoginActivity.lang.getString("areyousure")+" ?");
		alertDialog.setCancelable(false);
		alertDialog.setPositiveButton(LoginActivity.lang.getString("ok"),
				new DialogInterface.OnClickListener() {

			@Override
			public void onClick(DialogInterface dialog,
					int which) {

				alertwaiting.show();

				try{
					new Thread(){
						public void run() {
							MySqlDataAccessHelper mysqlHelper = new MySqlDataAccessHelper();
							int id = 0;
							try {
								mysqlHelper.open(LoginActivity.database);
								String sql1 = String.format("SELECT listapprove.Order FROM listapprove  WHERE IDEmployee = '%s' AND IDGroupApprove = '%s'",
										LoginActivity.emp.getIdemployee(),approvedoc.getiDGroupApprove());				
								ResultSet rs = mysqlHelper.executeQuery(sql1);
								while (rs.next())
									id = rs.getInt("listapprove.Order");
								String sql = "UPDATE listapprove SET IDStatus=1,DateApprove=NOW()," +
								"Description='"+etcomment.getText().toString()+"' WHERE IDEmployee='"
								+ LoginActivity.emp.getIdemployee()
								+ "' AND IDGroupApprove = '"
								+ approvedoc.getiDGroupApprove()
								+ "'";
								mysqlHelper.executeUpdate(sql);
								ListReferenceDAO.updateaccept(LoginActivity.emp.getIdemployee(),approvedoc.getiDGroupApprove(),mysqlHelper);
								updateDocument(approvedoc.getiDGroupApprove(), id + 1,mysqlHelper);
							} catch (Exception ex) {
								ex.printStackTrace();
							} finally {
								mysqlHelper.close();
							}

							uiHandler.post( new Runnable(){
								@Override
								public void run() {
									if(isUpdateRequired){
									}else{
										if(parentview.equals("notApprove")){
											Intent intent = new Intent(App_ViewForm12.this,App_NotApproveDocument.class);
											startActivity(intent);	
										}else if(parentview.equals("approveDoc")){
											Intent intent = new Intent(App_ViewForm12.this,App_ApprovedDocument.class);
											startActivity(intent);
										}else if(parentview.equals("declineDoc")){
											Intent intent = new Intent(App_ViewForm12.this,App_DeclineDocument.class);
											startActivity(intent);
										}else if(parentview.equals("referApprove")){
											Intent intent = new Intent(App_ViewForm12.this,App_ReferenceDoc_Approved.class);
											startActivity(intent);
										}else if(parentview.equals("referWait")){
											Intent intent = new Intent(App_ViewForm12.this,App_ReferenceDoc_Waiting.class);
											startActivity(intent);
										}else if(parentview.equals("docPending")){
											Intent intent = new Intent(App_ViewForm12.this,App_PendingDocument.class);
											startActivity(intent);
										}else{
											Intent intent = new Intent(App_ViewForm12.this,App_MeetingDocPending.class);
											startActivity(intent);
										}
										finish();
										alertwaiting.cancel();		                               
									}
								}
							} );
						}
					}.start();
				}catch (Exception e) {}
			}
		});

		alertDialog.setNegativeButton(LoginActivity.lang.getString("cancel"),
				new DialogInterface.OnClickListener() {

			@Override
			public void onClick(DialogInterface dialog,
					int which) {
			}
		});
		AlertDialog alert1 = alertDialog.create();
		alert1.show();

	}

	void acceptRefer(){
		AlertDialog.Builder alertDialog = new AlertDialog.Builder(App_ViewForm12.this);
		alertDialog.setTitle(LoginActivity.lang.getString("accept"));
		alertDialog.setMessage(LoginActivity.lang.getString("areyousure")+" ?");
		alertDialog.setCancelable(false);
		alertDialog.setPositiveButton(LoginActivity.lang.getString("ok"),
				new DialogInterface.OnClickListener() {

			@Override
			public void onClick(DialogInterface dialog,
					int which) {

				alertwaiting.show();

				try{
					new Thread(){
						public void run() {
							ListReferenceDAO.acceptReference(approvedoc.getiDGroupApprove(), LoginActivity.emp.getIdemployee(), LoginActivity.database);
							uiHandler.post( new Runnable(){
								@Override
								public void run() {
									if(isUpdateRequired){
									}else{
										if(parentview.equals("notApprove")){
											Intent intent = new Intent(App_ViewForm12.this,App_NotApproveDocument.class);
											startActivity(intent);	
										}else if(parentview.equals("approveDoc")){
											Intent intent = new Intent(App_ViewForm12.this,App_ApprovedDocument.class);
											startActivity(intent);
										}else if(parentview.equals("declineDoc")){
											Intent intent = new Intent(App_ViewForm12.this,App_DeclineDocument.class);
											startActivity(intent);
										}else if(parentview.equals("referApprove")){
											Intent intent = new Intent(App_ViewForm12.this,App_ReferenceDoc_Approved.class);
											startActivity(intent);
										}else if(parentview.equals("referWait")){
											Intent intent = new Intent(App_ViewForm12.this,App_ReferenceDoc_Waiting.class);
											startActivity(intent);
										}else if(parentview.equals("docPending")){
											Intent intent = new Intent(App_ViewForm12.this,App_PendingDocument.class);
											startActivity(intent);
										}else{
											Intent intent = new Intent(App_ViewForm12.this,App_MeetingDocPending.class);
											startActivity(intent);
										}
										finish();
										alertwaiting.cancel();		                               
									}
								}
							} );
						}
					}.start();
				}catch (Exception e) {}
			}
		});

		alertDialog.setNegativeButton(LoginActivity.lang.getString("cancel"),
				new DialogInterface.OnClickListener() {

			@Override
			public void onClick(DialogInterface dialog,
					int which) {
			}
		});
		AlertDialog alert1 = alertDialog.create();
		alert1.show();

	}

	void updateDocument(String idGroup, int id,MySqlDataAccessHelper mysqlHelper) {
		try {
			int pending = 0;
			String sql = String.format("SELECT listapprove.IDStatus FROM listapprove,approvedoc "
					+ " WHERE listapprove.IDGroupApprove = approvedoc.IDGroupApprove"
					+ " AND listapprove.IDGroupApprove = '%s'", idGroup);
			ResultSet rs = mysqlHelper.executeQuery(sql);
			while (rs.next()) {
				if (rs.getInt("listapprove.IDStatus") == 4)
					pending++;
			}
			if (pending == 0) {
				sql="UPDATE approvedoc SET IDStatus=1,TimeApprove = NOW() WHERE IDGroupApprove = '"+idGroup+"'";
				mysqlHelper.executeUpdate(sql);
			} else {
				sql = "UPDATE listapprove SET IDStatus=2 WHERE listapprove.IDGroupApprove='"
					+ idGroup + "' AND listapprove.Order=" + id;
				mysqlHelper.executeUpdate(sql);
			}
		} catch (Exception e) {
			e.printStackTrace();
		} 
	}

	void decline(){
		AlertDialog.Builder alertDialog = new AlertDialog.Builder(App_ViewForm12.this);
		alertDialog.setTitle(LoginActivity.lang.getString("Decline"));
		alertDialog.setMessage(LoginActivity.lang.getString("areyousure")+" ?");
		alertDialog.setCancelable(false);
		alertDialog.setPositiveButton(LoginActivity.lang.getString("ok"),
				new DialogInterface.OnClickListener() {

			@Override
			public void onClick(DialogInterface dialog,
					int which) {

				alertwaiting.show();

				try{
					new Thread(){
						public void run() {
							MySqlDataAccessHelper mysqlHelper = new MySqlDataAccessHelper();
							try {
								mysqlHelper.open(LoginActivity.database);
								String sql = String.format("UPDATE listapprove SET IDStatus=3,DateApprove=NOW()," +
										"Description='"+etcomment.getText().toString()+"' WHERE IDEmployee = '%s' " + 
										" AND IDGroupApprove = '%s'",LoginActivity.emp.getIdemployee(),approvedoc.getiDGroupApprove());			
								mysqlHelper.executeUpdate(sql);			
								sql = String.format("UPDATE approvedoc SET IDStatus=3,TimeApprove = NOW() WHERE IDGroupApprove = '%s'",approvedoc.getiDGroupApprove());					
								mysqlHelper.executeUpdate(sql);			
							} catch (Exception e) {
								e.printStackTrace();
							} finally {
								mysqlHelper.close();
							}


							uiHandler.post( new Runnable(){
								@Override
								public void run() {
									if(isUpdateRequired){
									}else{
										if(parentview.equals("notApprove")){
											Intent intent = new Intent(App_ViewForm12.this,App_NotApproveDocument.class);
											startActivity(intent);	
										}else if(parentview.equals("approveDoc")){
											Intent intent = new Intent(App_ViewForm12.this,App_ApprovedDocument.class);
											startActivity(intent);
										}else if(parentview.equals("declineDoc")){
											Intent intent = new Intent(App_ViewForm12.this,App_DeclineDocument.class);
											startActivity(intent);
										}else if(parentview.equals("referApprove")){
											Intent intent = new Intent(App_ViewForm12.this,App_ReferenceDoc_Approved.class);
											startActivity(intent);
										}else if(parentview.equals("referWait")){
											Intent intent = new Intent(App_ViewForm12.this,App_ReferenceDoc_Waiting.class);
											startActivity(intent);
										}else if(parentview.equals("docPending")){
											Intent intent = new Intent(App_ViewForm12.this,App_PendingDocument.class);
											startActivity(intent);
										}else{
											Intent intent = new Intent(App_ViewForm12.this,App_MeetingDocPending.class);
											startActivity(intent);
										}	
										finish();
										alertwaiting.cancel();
									}
								}
							} );
						}
					}.start();
				}catch (Exception e) {}
			}
		});

		alertDialog.setNegativeButton(LoginActivity.lang.getString("cancel"),
				new DialogInterface.OnClickListener() {

			@Override
			public void onClick(DialogInterface dialog,
					int which) {
			}
		});
		AlertDialog alert1 = alertDialog.create();
		alert1.show();

	}



	public void processAddRefer(){
		LayoutInflater inflater = (LayoutInflater) App_ViewForm12.this.getSystemService(LAYOUT_INFLATER_SERVICE);          
		final View textEntryView = inflater.inflate(R.layout.app_addreferall, null);

		lstdepart=(Spinner)textEntryView.findViewById(R.id.lstdepartlist);
		lstrefer=(ListView)textEntryView.findViewById(R.id.listaddrefer);

		referadapter= new App_Adapter_AddRefer(App_ViewForm12.this,referlist,12);		
		lstrefer.setAdapter(referadapter);		
		LayoutParams paramsRe = (LayoutParams) lstrefer.getLayoutParams();
		paramsRe.height = LoginActivity.screenheight;
		lstrefer.setLayoutParams(paramsRe);

		departlist=NotApproveDAO.getListDepartment1(LoginActivity.lang.getString("choosedepartment"),LoginActivity.typeLang, LoginActivity.database);
		final ArrayAdapter<DepartmentLang> departadapter=new ArrayAdapter<DepartmentLang>(App_ViewForm12.this,android.R.layout.simple_spinner_dropdown_item,departlist);
		departadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		lstdepart.setAdapter(departadapter);

		AlertDialog.Builder builder = new AlertDialog.Builder(App_ViewForm12.this);
		builder.setTitle(LoginActivity.lang.getString("reference"));
		builder.setCancelable(false);
		builder.setView(textEntryView);


		lstdepart.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				if(arg2!=0){
					departmentchoose = (DepartmentLang)arg0.getItemAtPosition(arg2);

					LayoutInflater inflater_pop = (LayoutInflater)getWindow().getContext().getSystemService(LAYOUT_INFLATER_SERVICE);          
					View textEntryView_pop= inflater_pop.inflate(R.layout.adapter_list_member, null);
					ListView lst_pop_chooserefer = (ListView)textEntryView_pop.findViewById(R.id.listMember11);
					LayoutParams pr1=(LayoutParams)lst_pop_chooserefer.getLayoutParams();
					pr1.height=LoginActivity.screenheight;
					lst_pop_chooserefer.setLayoutParams(pr1);	

					emlist= NotApproveDAO.getListEmployeeSubRefer(departmentchoose.getId(), LoginActivity.database,referadapter.getStrid());
					emadapter= new ListEmployeeAdapter(getWindow().getContext(),emlist);
					lst_pop_chooserefer.setAdapter(emadapter);

					AlertDialog.Builder pop_builder1 = new AlertDialog.Builder(getWindow().getContext());
					pop_builder1.setTitle(LoginActivity.lang.getString("reference"));
					pop_builder1.setCancelable(false);
					pop_builder1.setView(textEntryView_pop);

					pop_builder1.setPositiveButton(LoginActivity.lang.getString("add11"), new DialogInterface.OnClickListener() {

						@Override
						public void onClick(DialogInterface dialog, int which) {
							if(emadapter.getListCheck()!=null && emadapter.getListCheck().size()>0){
								for(int i=0;i<emadapter.getListCheck().size();i++){
									Employee tememp=emadapter.getListCheck().get(i);
									referlist.add(tememp);
								}

								referadapter.notifyDataSetChanged();
							}
							lstdepart.setAdapter(departadapter);
						}

					});

					pop_builder1.setNegativeButton(LoginActivity.lang.getString("cancel"), new DialogInterface.OnClickListener(){

						@Override
						public void onClick(DialogInterface dialog, int which) {
							lstdepart.setAdapter(departadapter);
						}

					});

					AlertDialog alert_pop1 = pop_builder1.create();
					alert_pop1.show();

				}
			}

			@Override
			public void onNothingSelected(AdapterView<?> arg0) {
			}
		});

		builder.setNegativeButton(LoginActivity.lang.getString("cancel"), new DialogInterface.OnClickListener() {

			public void onClick(DialogInterface dialog, int which) {
				flagviewpopup=0;
				referlist=new ArrayList<Employee>();
				referlist.addAll(subreferlist);
			}
		});

		builder.setPositiveButton(LoginActivity.lang.getString("ok"), new DialogInterface.OnClickListener() {

			@Override
			public void onClick(DialogInterface dialog, int which) {

				final ArrayList<Employee> lstaddchooserefer = referadapter.getListrefer();
				if(lstaddchooserefer!=null && lstaddchooserefer.size()>0){
					alertwaiting.show();
					try{
						new Thread(){
							public void run() {
								ListReferenceDAO.delete(LoginActivity.emp.getIdemployee(), approvedoc.getiDGroupApprove(),LoginActivity.database);
								String sql="INSERT INTO list_reference(id_employee,id_manager,id_group,id_status) VALUES ";
								String temsql="";
								for(int i=0;i<lstaddchooserefer.size();i++){
									Employee tememp=lstaddchooserefer.get(i);
									if(temsql.equals("")){
										temsql="('"+tememp.getIdemployee()+"','"+LoginActivity.emp.getIdemployee()+"','"+approvedoc.getiDGroupApprove()+"',4)";
									}else{
										temsql+=",('"+tememp.getIdemployee()+"','"+LoginActivity.emp.getIdemployee()+"','"+approvedoc.getiDGroupApprove()+"',4)";
									}
								}
								sql+=temsql;
								ListReferenceDAO.insert(sql, LoginActivity.database);

								uiHandler.post( new Runnable(){
									@Override
									public void run() {
										if(isUpdateRequired){
										}else{
											adapterApprover = new ListApproveAdapter(getApplicationContext(),getAllListApproveByGroupID(), LoginActivity.lang, LoginActivity.emp, LoginActivity.database, LoginActivity.typeLang);
											lvapprove.setAdapter(adapterApprover);
											totalHeight_lstapp=0;
											for (int i = 0; i < adapterApprover.getCount(); i++) {
												View listItem = adapterApprover.getView(i, null, lvapprove);
												listItem.measure(0, 0);
												totalHeight_lstapp += listItem.getMeasuredHeight();
											}

											totalHeight_lstapp+= totalHeight_lstapp + (lvapprove.getDividerHeight() * (adapterApprover.getCount() - 1));
											if(totalHeight_lstapp<=0){
												params_lstapp.height =0;
												lvapprove.setLayoutParams(params_lstapp);
											}else{
												if(totalHeight_lstapp<200){
													params_lstapp.height=android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
													lvapprove.setLayoutParams(params_lstapp);
												}else{
													params_lstapp.height=200;
													lvapprove.setLayoutParams(params_lstapp);
												}
											}
											subreferlist=new ArrayList<Employee>();
											subreferlist.addAll(referlist);
											alertwaiting.cancel();
										}
									}
								} );
							}
						}.start();
					}catch (Exception e) {}
				}else{
					alertwaiting.show();
					try{
						new Thread(){
							public void run() {
								ListReferenceDAO.delete(LoginActivity.emp.getIdemployee(), approvedoc.getiDGroupApprove(),LoginActivity.database);

								uiHandler.post( new Runnable(){
									@Override
									public void run() {
										if(isUpdateRequired){
										}else{
											adapterApprover = new ListApproveAdapter(getApplicationContext(), getAllListApproveByGroupID(), LoginActivity.lang, LoginActivity.emp, LoginActivity.database, LoginActivity.typeLang);
											lvapprove.setAdapter(adapterApprover);
											totalHeight_lstapp=0;
											for (int i = 0; i < adapterApprover.getCount(); i++) {
												View listItem = adapterApprover.getView(i, null, lvapprove);
												listItem.measure(0, 0);
												totalHeight_lstapp += listItem.getMeasuredHeight();
											}

											totalHeight_lstapp+= totalHeight_lstapp + (lvapprove.getDividerHeight() * (adapterApprover.getCount() - 1));
											if(totalHeight_lstapp<=0){
												params_lstapp.height =0;
												lvapprove.setLayoutParams(params_lstapp);
											}else{
												if(totalHeight_lstapp<200){
													params_lstapp.height=android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
													lvapprove.setLayoutParams(params_lstapp);
												}else{
													params_lstapp.height=200;
													lvapprove.setLayoutParams(params_lstapp);
												}
											}
											subreferlist=new ArrayList<Employee>();
											subreferlist.addAll(referlist);
											alertwaiting.cancel();
										}
									}
								} );
							}
						}.start();
					}catch (Exception e) {}
				}

				flagviewpopup=0;
			}
		});

		AlertDialog alert = builder.create();
		alert.show();

	}


	@Override
	public void onBackPressed() {

		if(parentview.equals("notApprove")){
			
			App_ViewForm12.this.getAlertwaiting().show();
			try{
				new Thread(){
					public void run() {
						Intent intent = new Intent(App_ViewForm12.this,App_NotApproveDocument.class);
						startActivity(intent);
						App_ViewForm12.this.getUiHandler().post( new Runnable(){
							@Override
							public void run() {
								if(App_ViewForm12.this.isUpdateRequired()){
								}else{
									App_ViewForm12.this.getAlertwaiting().cancel();
								}
							}
						} );
					}
				}.start();
			}catch (Exception e) {}
		}else if(parentview.equals("approveDoc")){
			
			App_ViewForm12.this.getAlertwaiting().show();
			try{
				new Thread(){
					public void run() {
						Intent intent = new Intent(App_ViewForm12.this,App_ApprovedDocument.class);
						startActivity(intent);
						App_ViewForm12.this.getUiHandler().post( new Runnable(){
							@Override
							public void run() {
								if(App_ViewForm12.this.isUpdateRequired()){
								}else{
									App_ViewForm12.this.getAlertwaiting().cancel();
								}
							}
						} );
					}
				}.start();
			}catch (Exception e) {}
		}else if(parentview.equals("declineDoc")){
			
			App_ViewForm12.this.getAlertwaiting().show();
			try{
				new Thread(){
					public void run() {
						Intent intent = new Intent(App_ViewForm12.this,App_DeclineDocument.class);
						startActivity(intent);
						App_ViewForm12.this.getUiHandler().post( new Runnable(){
							@Override
							public void run() {
								if(App_ViewForm12.this.isUpdateRequired()){
								}else{
									App_ViewForm12.this.getAlertwaiting().cancel();
								}
							}
						} );
					}
				}.start();
			}catch (Exception e) {}
		}else if(parentview.equals("referApprove")){
			
			App_ViewForm12.this.getAlertwaiting().show();
			try{
				new Thread(){
					public void run() {
						Intent intent = new Intent(App_ViewForm12.this,App_ReferenceDoc_Approved.class);
						startActivity(intent);
						App_ViewForm12.this.getUiHandler().post( new Runnable(){
							@Override
							public void run() {
								if(App_ViewForm12.this.isUpdateRequired()){
								}else{
									App_ViewForm12.this.getAlertwaiting().cancel();
								}
							}
						} );
					}
				}.start();
			}catch (Exception e) {}
		}else if(parentview.equals("referWait")){
			
			App_ViewForm12.this.getAlertwaiting().show();
			try{
				new Thread(){
					public void run() {
						Intent intent = new Intent(App_ViewForm12.this,App_ReferenceDoc_Waiting.class);
						startActivity(intent);
						App_ViewForm12.this.getUiHandler().post( new Runnable(){
							@Override
							public void run() {
								if(App_ViewForm12.this.isUpdateRequired()){
								}else{
									App_ViewForm12.this.getAlertwaiting().cancel();
								}
							}
						} );
					}
				}.start();
			}catch (Exception e) {}
		}else if(parentview.equals("docPending")){
			
			App_ViewForm12.this.getAlertwaiting().show();
			try{
				new Thread(){
					public void run() {
						Intent intent = new Intent(App_ViewForm12.this,App_PendingDocument.class);
						startActivity(intent);
						App_ViewForm12.this.getUiHandler().post( new Runnable(){
							@Override
							public void run() {
								if(App_ViewForm12.this.isUpdateRequired()){
								}else{
									App_ViewForm12.this.getAlertwaiting().cancel();
								}
							}
						} );
					}
				}.start();
			}catch (Exception e) {}
		}else if(parentview.equals("my_approveDoc")){
			
			App_ViewForm12.this.getAlertwaiting().show();
			try{
				new Thread(){
					public void run() {
						Intent intent = new Intent(App_ViewForm12.this,My_App_ApproveDocument.class);
						startActivity(intent);
						App_ViewForm12.this.getUiHandler().post( new Runnable(){
							@Override
							public void run() {
								if(App_ViewForm12.this.isUpdateRequired()){
								}else{
									App_ViewForm12.this.getAlertwaiting().cancel();
								}
							}
						} );
					}
				}.start();
			}catch (Exception e) {}
		}else if(parentview.equals("my_declineDoc")){
			
			App_ViewForm12.this.getAlertwaiting().show();
			try{
				new Thread(){
					public void run() {
						Intent intent = new Intent(App_ViewForm12.this,My_App_DeclineDocument.class);
						startActivity(intent);
						App_ViewForm12.this.getUiHandler().post( new Runnable(){
							@Override
							public void run() {
								if(App_ViewForm12.this.isUpdateRequired()){
								}else{
									App_ViewForm12.this.getAlertwaiting().cancel();
								}
							}
						} );
					}
				}.start();
			}catch (Exception e) {}
		}else if(parentview.equals("my_meetingPending")){
			
			App_ViewForm12.this.getAlertwaiting().show();
			try{
				new Thread(){
					public void run() {
						Intent intent = new Intent(App_ViewForm12.this,My_App_MeetingSendingDocument.class);
						startActivity(intent);
						App_ViewForm12.this.getUiHandler().post( new Runnable(){
							@Override
							public void run() {
								if(App_ViewForm12.this.isUpdateRequired()){
								}else{
									App_ViewForm12.this.getAlertwaiting().cancel();
								}
							}
						} );
					}
				}.start();
			}catch (Exception e) {}
		}else if(parentview.equals("my_saveDoc")){
			
			App_ViewForm12.this.getAlertwaiting().show();
			try{
				new Thread(){
					public void run() {
						Intent intent = new Intent(App_ViewForm12.this,My_App_SaveDocument.class);
						startActivity(intent);
						App_ViewForm12.this.getUiHandler().post( new Runnable(){
							@Override
							public void run() {
								if(App_ViewForm12.this.isUpdateRequired()){
								}else{
									App_ViewForm12.this.getAlertwaiting().cancel();
								}
							}
						} );
					}
				}.start();
			}catch (Exception e) {}
		}else if(parentview.equals("my_sendingDoc")){
			
			App_ViewForm12.this.getAlertwaiting().show();
			try{
				new Thread(){
					public void run() {
						Intent intent = new Intent(App_ViewForm12.this,My_App_SendingDocument.class);
						startActivity(intent);
						App_ViewForm12.this.getUiHandler().post( new Runnable(){
							@Override
							public void run() {
								if(App_ViewForm12.this.isUpdateRequired()){
								}else{
									App_ViewForm12.this.getAlertwaiting().cancel();
								}
							}
						} );
					}
				}.start();
			}catch (Exception e) {}
		}else if(parentview.equals("recycle_pending")){
			
			App_ViewForm12.this.getAlertwaiting().show();
			try{
				new Thread(){
					public void run() {
						Intent intent = new Intent(App_ViewForm12.this,My_Sending_RecycleBin.class);
						startActivity(intent);
						App_ViewForm12.this.getUiHandler().post( new Runnable(){
							@Override
							public void run() {
								if(App_ViewForm12.this.isUpdateRequired()){
								}else{
									App_ViewForm12.this.getAlertwaiting().cancel();
								}
							}
						} );
					}
				}.start();
			}catch (Exception e) {}
		}else if(parentview.equals("recyle_app")){
			
			App_ViewForm12.this.getAlertwaiting().show();
			try{
				new Thread(){
					public void run() {
						Intent intent = new Intent(App_ViewForm12.this,My_Approve_RecycleBin.class);
						startActivity(intent);
						App_ViewForm12.this.getUiHandler().post( new Runnable(){
							@Override
							public void run() {
								if(App_ViewForm12.this.isUpdateRequired()){
								}else{
									App_ViewForm12.this.getAlertwaiting().cancel();
								}
							}
						} );
					}
				}.start();
			}catch (Exception e) {}
		}else if(parentview.equals("library")){
			
			App_ViewForm12.this.getAlertwaiting().show();
			try{
				new Thread(){
					public void run() {
						Intent intent = new Intent(App_ViewForm12.this,Library_Label_Item.class);
						intent.putExtra("label", label);
						startActivity(intent);
						App_ViewForm12.this.getUiHandler().post( new Runnable(){
							@Override
							public void run() {
								if(App_ViewForm12.this.isUpdateRequired()){
								}else{
									App_ViewForm12.this.getAlertwaiting().cancel();
								}
							}
						} );
					}
				}.start();
			}catch (Exception e) {}
		}else{
			
			App_ViewForm12.this.getAlertwaiting().show();
			try{
				new Thread(){
					public void run() {
						Intent intent = new Intent(App_ViewForm12.this,App_MeetingDocPending.class);
						startActivity(intent);
						App_ViewForm12.this.getUiHandler().post( new Runnable(){
							@Override
							public void run() {
								if(App_ViewForm12.this.isUpdateRequired()){
								}else{
									App_ViewForm12.this.getAlertwaiting().cancel();
								}
							}
						} );
					}
				}.start();
			}catch (Exception e) {}
		}
		finish();
	}

	void view_declineDoc_delete(){
		AlertDialog.Builder alertDialog = new AlertDialog.Builder(App_ViewForm12.this);
		alertDialog.setTitle(LoginActivity.lang.getString("Delete"));
		alertDialog.setMessage(LoginActivity.lang.getString("areyousure")+" ?");
		alertDialog.setCancelable(false);
		alertDialog.setPositiveButton(LoginActivity.lang.getString("ok"),
				new DialogInterface.OnClickListener() {

			@Override
			public void onClick(DialogInterface dialog,
					int which) {

				alertwaiting.show();

				try{
					new Thread(){
						public void run() {
							MySqlDataAccessHelper mysqlHelper = new MySqlDataAccessHelper();
							try {
								mysqlHelper.open(LoginActivity.database);
								String sql = "UPDATE approvedoc set IDStatus = 6 WHERE IDApproveDoc = '"+approvedoc.getiDApproveDoc()+"'";			
								mysqlHelper.executeUpdate(sql);			
							} catch (Exception e) {
								e.printStackTrace();
							} finally {
								mysqlHelper.close();
							}


							uiHandler.post( new Runnable(){
								@Override
								public void run() {
									if(isUpdateRequired){
									}else{
										if(parentview.equals("my_declineDoc")){
											Intent intent = new Intent(App_ViewForm12.this,My_App_DeclineDocument.class);
											startActivity(intent);	
											finish();
										}else if(parentview.equals("my_saveDoc")){
											Intent intent = new Intent(App_ViewForm12.this,My_App_SaveDocument.class);
											startActivity(intent);
											finish();
										}
										alertwaiting.cancel();
									}
								}
							} );
						}
					}.start();
				}catch (Exception e) {}
			}
		});

		alertDialog.setNegativeButton(LoginActivity.lang.getString("cancel"),
				new DialogInterface.OnClickListener() {

			@Override
			public void onClick(DialogInterface dialog,
					int which) {
			}
		});
		AlertDialog alert1 = alertDialog.create();
		alert1.show();
	}

	void view_saveDoc_delete(){
		AlertDialog.Builder alertDialog = new AlertDialog.Builder(App_ViewForm12.this);
		alertDialog.setTitle(LoginActivity.lang.getString("Delete"));
		alertDialog.setMessage(LoginActivity.lang.getString("areyousure")+" ?");
		alertDialog.setCancelable(false);
		alertDialog.setPositiveButton(LoginActivity.lang.getString("ok"),
				new DialogInterface.OnClickListener() {

			@Override
			public void onClick(DialogInterface dialog,
					int which) {

				alertwaiting.show();

				try{
					new Thread(){
						public void run() {
							MySqlDataAccessHelper mysqlHelper = new MySqlDataAccessHelper();
							try {
								mysqlHelper.open(LoginActivity.database);
								String sql = "DELETE FROM approvedoc WHERE IDApproveDoc = '"+approvedoc.getiDApproveDoc()+"'";			
								mysqlHelper.executeUpdate(sql);			
							} catch (Exception e) {
								e.printStackTrace();
							} finally {
								mysqlHelper.close();
							}


							uiHandler.post( new Runnable(){
								@Override
								public void run() {
									if(isUpdateRequired){
									}else{
										if(parentview.equals("my_declineDoc")){
											Intent intent = new Intent(App_ViewForm12.this,My_App_DeclineDocument.class);
											startActivity(intent);
											finish();
										}else if(parentview.equals("my_saveDoc")){
											Intent intent = new Intent(App_ViewForm12.this,My_App_SaveDocument.class);
											startActivity(intent);
											finish();
										}
										alertwaiting.cancel();
									}
								}
							} );
						}
					}.start();
				}catch (Exception e) {}
			}
		});

		alertDialog.setNegativeButton(LoginActivity.lang.getString("cancel"),
				new DialogInterface.OnClickListener() {

			@Override
			public void onClick(DialogInterface dialog,
					int which) {
			}
		});
		AlertDialog alert1 = alertDialog.create();
		alert1.show();
	}



	void view_send(){
		inflater_pop_addapprover = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);          
		textEntryView_pop_addapprover = inflater_pop_addapprover.inflate(R.layout.app_pop_addapprover, null);

		final Spinner spindepartment=(Spinner)textEntryView_pop_addapprover.findViewById(R.id.spin_department);
		lv_pop_approver=(ListView)textEntryView_pop_addapprover.findViewById(R.id.lv_approver);
		LayoutParams pr=(LayoutParams)lv_pop_approver.getLayoutParams();
		pr.height=LoginActivity.screenheight;
		lv_pop_approver.setLayoutParams(pr);
		chooseapproveradapter= new App_Pop_AdapterApproverAll(App_ViewForm12.this, approverlist,LoginActivity.typeLang,LoginActivity.database,LoginActivity.lang,LoginActivity.screenheight,12);
		lv_pop_approver.setAdapter(chooseapproveradapter);

		ArrayList<DepartmentLang> lstpopdepart=NotApproveDAO.getListDepartment1(LoginActivity.lang.getString("choosedepartment"),LoginActivity.typeLang, LoginActivity.database);
		final ArrayAdapter<DepartmentLang> departadapter=new ArrayAdapter<DepartmentLang>(App_ViewForm12.this,android.R.layout.simple_spinner_dropdown_item,lstpopdepart);
		departadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		spindepartment.setAdapter(departadapter);

		builder_pop_addapprover = new AlertDialog.Builder(App_ViewForm12.this);
		builder_pop_addapprover.setTitle(LoginActivity.lang.getString("add_approver"));
		builder_pop_addapprover.setCancelable(false);
		builder_pop_addapprover.setView(textEntryView_pop_addapprover);

		spindepartment.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> arg0, View arg1,
					int arg2, long arg3) {
				if(arg2!=0){
					DepartmentLang departmentchoose = (DepartmentLang)arg0.getItemAtPosition(arg2);

					LayoutInflater inflater_pop_viewchooseaddapprover = (LayoutInflater)getWindow().getContext().getSystemService(LAYOUT_INFLATER_SERVICE);          
					View textEntryView_pop_viewchooseaddapprover = inflater_pop_viewchooseaddapprover.inflate(R.layout.adapter_list_member, null);
					ListView lvchooseapprover = (ListView)textEntryView_pop_viewchooseaddapprover.findViewById(R.id.listMember11);
					LayoutParams pr1=(LayoutParams)lvchooseapprover.getLayoutParams();
					pr1.height=LoginActivity.screenheight;
					lvchooseapprover.setLayoutParams(pr1);
					ArrayList<Employee> emlist_chooseapprover= NotApproveDAO.getListEmployeeSubRefer(departmentchoose.getId(), LoginActivity.database,chooseapproveradapter.getStrid());
					final ListEmployeeAdapter emadapter_chooseapprover= new ListEmployeeAdapter(getWindow().getContext(),emlist_chooseapprover);
					lvchooseapprover.setAdapter(emadapter_chooseapprover);

					AlertDialog.Builder builder_pop_viewchooseaddapprover = new AlertDialog.Builder(getWindow().getContext());
					builder_pop_viewchooseaddapprover.setTitle(LoginActivity.lang.getString("selecttheapprover"));
					builder_pop_viewchooseaddapprover.setCancelable(false);
					builder_pop_viewchooseaddapprover.setView(textEntryView_pop_viewchooseaddapprover);


					builder_pop_viewchooseaddapprover.setPositiveButton(LoginActivity.lang.getString("ok"), new DialogInterface.OnClickListener() {

						@Override
						public void onClick(DialogInterface dialog, int which) {
							ArrayList<Employee> lstcheck =(ArrayList<Employee>) emadapter_chooseapprover.getListCheck();
							if(lstcheck!=null & lstcheck.size()>0){
								for(int i=0;i<lstcheck.size();i++){
									approverlist.add(new ListEmployee(lstcheck.get(i), new ArrayList<Employee>()));
								}
							}					
							chooseapproveradapter= new App_Pop_AdapterApproverAll(App_ViewForm12.this, approverlist,LoginActivity.typeLang,LoginActivity.database,LoginActivity.lang,LoginActivity.screenheight,12);
							lv_pop_approver.setAdapter(chooseapproveradapter);
							spindepartment.setAdapter(departadapter);
						}
					});

					builder_pop_viewchooseaddapprover.setNegativeButton(LoginActivity.lang.getString("cancel"),
							new DialogInterface.OnClickListener() {
						@Override
						public void onClick(DialogInterface dialog, int which) {
							spindepartment.setAdapter(departadapter);
						}
					});

					AlertDialog alert_pop_viewchooseaddapprover = builder_pop_viewchooseaddapprover.create();
					alert_pop_viewchooseaddapprover.show();

				}

			}

			@Override
			public void onNothingSelected(AdapterView<?> arg0) {

			}

		});

		builder_pop_addapprover.setPositiveButton(LoginActivity.lang.getString("add_approver"), new DialogInterface.OnClickListener() {

			@Override
			public void onClick(DialogInterface dialog, int which) {
				flagviewpopup=0;
				final List<ListEmployee> lapp=chooseapproveradapter.getListchoosetapprover();
				if(lapp!=null && lapp.size()>0){
					alertwaiting.show();

					try{
						new Thread(){
							public void run() {

								String strapp="";
								String strrefer="";
								String sql="INSERT INTO listapprove(IDGroupApprove,IDEmployee,IDtypeApprove,`Order`,IDStatus) ";
								String sqlrefer="INSERT INTO list_reference(id_employee,id_manager,id_group,id_status) ";
								String id = new Date().getTime()+"";

								for(int i=0;i<lapp.size();i++){
									if(strapp.equals("")){
										strapp = "VALUES('"+id+"','"+lapp.get(i).getEmpapprover().getIdemployee()+"',1,"+(i+1)+","+((i+2)==2?2:4)+")";
									}else{
										strapp +=",('"+id+"','"+lapp.get(i).getEmpapprover().getIdemployee()+"',1,"+(i+1)+","+((i+2)==2?2:4)+")";
									}

									List<Employee> lrefer= lapp.get(i).getListrefer();
									if(lrefer!=null && lrefer.size()>0){
										for(int k=0;k<lrefer.size();k++){
											if(lrefer.get(k).isChecked()==true){
												if(strrefer.equals("")){
													strrefer = "VALUES('"+lrefer.get(k).getIdemployee()+"','"+lapp.get(i).getEmpapprover().getIdemployee()+"','"+id+"',4)";
												}else{
													strrefer +=",('"+lrefer.get(k).getIdemployee()+"','"+lapp.get(i).getEmpapprover().getIdemployee()+"','"+id+"',4)";
												}
											}
										}
									}

								}

								if(!strapp.equals("")){
									sql+=strapp;
									MySqlDataAccessHelper mysqlHelper = new MySqlDataAccessHelper();
									try {
										mysqlHelper.open(LoginActivity.database);
										if(mysqlHelper.executeUpdate(sql)>0){
											if(!strrefer.equals("")){
												sqlrefer+=strrefer;
												mysqlHelper.executeUpdate(sqlrefer);
											}
											sql="UPDATE approvedoc SET IDGroupApprove='"+id+"',IDStatus=2,Timecreate = NOW() WHERE IDApproveDoc='"+approvedoc.getiDApproveDoc()+"'";
											mysqlHelper.executeUpdate(sql);
										}
									} catch (Exception e) {
										e.printStackTrace();
									} finally {
										mysqlHelper.close();
									}
								}



								uiHandler.post( new Runnable(){
									@Override
									public void run() {
										if(isUpdateRequired){
										}else{
											if(parentview.equals("my_saveDoc")){
												Intent intent = new Intent(App_ViewForm12.this,My_App_SaveDocument.class);
												startActivity(intent);
												finish();
											}
											alertwaiting.cancel();
										}
									}
								} );
							}
						}.start();
					}catch (Exception e) {}

				}

			}
		});

		builder_pop_addapprover.setNegativeButton(LoginActivity.lang.getString("cancel"),
				new DialogInterface.OnClickListener() {
			@Override
			public void onClick(DialogInterface dialog, int which) {
				flagviewpopup=0;
				approverlist = new ArrayList<ListEmployee>();
			}
		});

		alert_pop_addapprover = builder_pop_addapprover.create();
		alert_pop_addapprover.show();

	}

	public OnClickListener processBack = new OnClickListener() {

		@Override
		public void onClick(View arg0) {
			buttonBack.setBackgroundResource(R.drawable.bg_back_pressed);
			if(parentview.equals("notApprove")){
				Intent intent = new Intent(App_ViewForm12.this,App_NotApproveDocument.class);
				startActivity(intent);
			}else if(parentview.equals("approveDoc")){
				Intent intent = new Intent(App_ViewForm12.this,App_ApprovedDocument.class);
				startActivity(intent);
			}else if(parentview.equals("declineDoc")){
				Intent intent = new Intent(App_ViewForm12.this,App_DeclineDocument.class);
				startActivity(intent);
			}else if(parentview.equals("referApprove")){
				Intent intent = new Intent(App_ViewForm12.this,App_ReferenceDoc_Approved.class);
				startActivity(intent);
			}else if(parentview.equals("referWait")){
				Intent intent = new Intent(App_ViewForm12.this,App_ReferenceDoc_Waiting.class);
				startActivity(intent);
			}else if(parentview.equals("docPending")){
				Intent intent = new Intent(App_ViewForm12.this,App_PendingDocument.class);
				startActivity(intent);
			}else if(parentview.equals("my_approveDoc")){
				Intent intent = new Intent(App_ViewForm12.this,My_App_ApproveDocument.class);
				startActivity(intent);
			}else if(parentview.equals("my_declineDoc")){
				Intent intent = new Intent(App_ViewForm12.this,My_App_DeclineDocument.class);
				startActivity(intent);
			}else if(parentview.equals("my_meetingPending")){
				Intent intent = new Intent(App_ViewForm12.this,My_App_MeetingSendingDocument.class);
				startActivity(intent);
			}else if(parentview.equals("my_saveDoc")){
				Intent intent = new Intent(App_ViewForm12.this,My_App_SaveDocument.class);
				startActivity(intent);
			}else if(parentview.equals("my_sendingDoc")){
				Intent intent = new Intent(App_ViewForm12.this,My_App_SendingDocument.class);
				startActivity(intent);
			}else if(parentview.equals("recycle_pending")){
				Intent intent = new Intent(App_ViewForm12.this,My_Sending_RecycleBin.class);
				startActivity(intent);
			}else if(parentview.equals("recyle_app")){
				Intent intent = new Intent(App_ViewForm12.this,My_Approve_RecycleBin.class);
				startActivity(intent);
			}else if(parentview.equals("library")){
				Intent intent = new Intent(App_ViewForm12.this,Library_Label_Item.class);
				intent.putExtra("label", label);
				startActivity(intent);
			}else{
				Intent intent = new Intent(App_ViewForm12.this,App_MeetingDocPending.class);
				startActivity(intent);
			}
			finish();
		}
	};
	
	public void processRestore(){
		AlertDialog.Builder builder = new AlertDialog.Builder(App_ViewForm12.this);
		builder.setTitle(LoginActivity.lang.getString("restore"));
		builder.setMessage(LoginActivity.lang.getString("areyousure")+" ?");
		builder.setCancelable(false);
		builder.setPositiveButton(LoginActivity.lang.getString("ok"), new DialogInterface.OnClickListener() {

			@Override
			public void onClick(DialogInterface arg0, int arg1) {
				flagviewpopup=0;
				alertwaiting.show();
				try{
					new Thread(){
						public void run(){
							final boolean kq=ApproveDocDao.restore(approvedoc, LoginActivity.database);
							uiHandler.post(new Runnable() {
								@Override
								public void run() {
									if(isUpdateRequired){
									}else{
										if(kq==true){
											Intent intent = new Intent(App_ViewForm12.this,My_Sending_RecycleBin.class);
											startActivity(intent);
										}
										alertwaiting.cancel();
									}
								}
							});
						}
					}.start();
				}catch(Exception e){}
			}
		});
		builder.setNegativeButton(LoginActivity.lang.getString("cancel"), new DialogInterface.OnClickListener() {

			@Override
			public void onClick(DialogInterface arg0, int arg1) {
				flagviewpopup=0;
			}
		});
		AlertDialog alertDialog = builder.create();
		alertDialog.show();
	}
}